package com.tt.converter;

import org.springframework.core.convert.converter.Converter;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 字符串转Date
 * @author 青青
 */
public class StringToDateConverter implements Converter<String, Date>
{
    @Override
    public Date convert(String source)
    {
        if(source == null){
            throw new RuntimeException("请传入参数！");
        }
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try
        {
            return df.parse(source);
        } catch (Exception e)
        {
            throw new RuntimeException("类型转换异常");
        }
    }
}
